﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL.Abstract;

namespace DAL.Classes
{
    public class TagDAL: abstractDAL
    {
        public List<Tag> getAllTags()
        {
            try
            {
                return  (from t in Wiki.Tags select t).ToList();
            }
            catch (Exception)
            {
                
                throw;
            }
        }

        public Tag getTagByID(int id)
        {
            try
            {
                return (from t in Wiki.Tags where t.idTag == id select t).SingleOrDefault();
            }
            catch (Exception)
            {

                throw;
            }
        }

        public List<Tag> getTagsByPostNew(PostNew postNew)
        {
            try
            {
                return (from t in Wiki.Tags
                        join tp in Wiki.TagPostNews on t.idTag equals tp.idTag
                        where tp.idPostNew == postNew.idPostNew
                        select t).ToList();
            }
            catch (Exception)
            {
                
                throw;
            }
        }

        public void insertTag(Tag tag)
        {
            try
            {
                Wiki.Tags.InsertOnSubmit(tag);
                Wiki.SubmitChanges();
            }
            catch (Exception)
            {
                
                throw;
            }
        }

    }
}
